import Image
import os

##########################################################################################
#		USER INPUT
##########################################################################################

#WHAT IS THE IMAGEMAGICK COMMAND?
cmd = 'convert'

#WHAT IMAGE?
filename = "familylines.png"

#FINAL RATIO (ASSUMING AN ORIGINAL IN LANDSCAPE)?
finalwidth = 100
finalheight = 10

##########################################################################################

#FINAL RATIO
ratio = finalwidth / finalheight

#SET GLOBAL TO STORE IF IMAGE IS PORTRAIT OR LANDSCAPE
portrait = -1

#OPEN FILE
im = Image.open(filename)
type = im.format.lower()
#SPLIT THE FILE EXTENSION OFF THE FILENAME
print "Filename: ", filename
im_name = filename.split('.')[0]

#FIND THE SIZE
size = im.size
width = size[0]
height = size[1]
print "Width: ",width, " Height: ", height

#WORK OUT IF PORTRAIT OR LANDSCAPE
if height > width :
	portrait = 1
	print "Image is: Portrait"
#	# IF PORTRAIT ROTATE THE IMAGE AND THEN
#	# SET THE DIMENSIONS AGAIN
#	im = im.rotate(90)
#	width = im.size[0]
#	height = im.size[1]
	os.quit()
else:
	portrait = 0
	print "Image is: Landscape"
	print "Rotating..."
	
#WORK OUT THE SIZE OF THE NEW IMAGE AND CUT IT OUT
new_height = width / ratio
